import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:BeeApp/MainPage/http_request.dart';
import 'package:flutter/material.dart';

class CarAlipayPage extends StatefulWidget {
  CarAlipayPage({Key key}) : super(key: key);

  @override
  _CarAlipayPageState createState() => _CarAlipayPageState();
}

class _CarAlipayPageState extends State<CarAlipayPage> {
  final nameText = TextEditingController();
  final codeText = TextEditingController();

  Widget lineView() {
    return Container(
      height: 1,
      width: 900,
      color: Colors.grey[300],
    );
  }

  Text labelText(String str) {
    return Text(
      str,
      style: TextStyle(
        color: Color(0xFF333333),
        fontSize: setFontSize(30),
        fontWeight: FontWeight.bold,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: getAppBar(context, "绑定收款账号"),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Container(
          padding: EdgeInsets.only(
            left: setWidth(30),
            right: setWidth(30),
          ),
          child: ListView(
            children: <Widget>[
              Container(height: 10, color: Color(0xFFFAFAFA)),
              SizedBox(height: setHeight(30)),
              Text(
                "支付宝账号",
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: setFontSize(34),
                  fontWeight: FontWeight.bold,
                ),
              ),
              SizedBox(height: setHeight(20)),
              textView("账    号：", "请输入账号", codeText),
              lineView(),
              SizedBox(height: setHeight(10)),
              textView("姓    名：", "请输入姓名", nameText),
              lineView(),
              SizedBox(height: setHeight(100)),
              btnView(),
            ],
          ),
        ),
      ),
    );
  }

  Widget textView(
    String string,
    String hintStr,
    TextEditingController controller,
  ) {
    return Container(
      color: Colors.white,
      child: Row(
        children: [
          labelText(string),
          SizedBox(width: 10),
          Expanded(
              child: TextField(
            controller: controller,
            textAlign: TextAlign.start,
            cursorColor: Colors.grey[400], //设置光标
            decoration: InputDecoration(
                border: InputBorder.none,
                hintText: hintStr,
                hintStyle: TextStyle(
                    fontSize: setFontSize(30), color: Color(0xFFAEAEAE))),
            style:
                TextStyle(fontSize: setFontSize(30), color: Color(0xFFAEAEAE)),
          )),
        ],
      ),
    );
  }

  Widget btnView() {
    return Container(
      alignment: Alignment.center,
      child: InkWell(
        child: Container(
          width: setWidth(300),
          alignment: Alignment.center,
          padding: EdgeInsets.all(setHeight(20)),
          decoration: BoxDecoration(
            color: Color(0xFFFF8629),
            borderRadius: BorderRadius.all(Radius.circular(10)),
            border: Border.all(color: Colors.black, width: 2), //边框
          ),
          child: Text(
            "绑定支付宝",
            style: TextStyle(
              color: Color(0xFF222222),
              fontSize: setFontSize(34),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        onTap: () {
          print("确认发货");
          removeFocus(context);
          showLoading(context);
          DioUtils.postHttp(
            context,
            "Usercommon/bind_alipay",
            parameters: {
              "token": getData("token"),
              "alipay_account": codeText.text,
              "realname": nameText.text
            },
            onSuccess: (t) {
              print(t);
              dismissLoading(context);
              showToast(t["msg"]);
              Navigator.pop(context);
            },
            onError: (error) {
              dismissLoading(context);
              print(error);
            },
          );
        },
      ),
    );
  }
}
